package com.ruoyi.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.system.domain.SysIdentityType;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.SysCompanyType;
import com.ruoyi.system.service.ISysCompanyTypeService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 企业类型Controller
 * 
 * @author ruoyi
 * @date 2024-07-30
 */
@RestController
@RequestMapping("/system/companytype")
public class SysCompanyTypeController extends BaseController
{
    @Autowired
    private ISysCompanyTypeService sysCompanyTypeService;

    /**
     * 查询企业类型列表
     */
    @PreAuthorize("@ss.hasPermi('system:companytype:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysCompanyType sysCompanyType)
    {
        startPage();
        List<SysCompanyType> list = sysCompanyTypeService.selectSysCompanyTypeList(sysCompanyType);
        return getDataTable(list);
    }

    /**
     * 查询企业类型列表
     */
    @PreAuthorize("@ss.hasPermi('system:companytype:lists')")
    @GetMapping("/lists")
    public AjaxResult lists(SysCompanyType sysCompanyType)
    {
        List<SysCompanyType> list = sysCompanyTypeService.selectSysCompanyTypeList(sysCompanyType);
        return success(list);
    }

    /**
     * 导出企业类型列表
     */
    @PreAuthorize("@ss.hasPermi('system:companytype:export')")
    @Log(title = "企业类型", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysCompanyType sysCompanyType)
    {
        List<SysCompanyType> list = sysCompanyTypeService.selectSysCompanyTypeList(sysCompanyType);
        ExcelUtil<SysCompanyType> util = new ExcelUtil<SysCompanyType>(SysCompanyType.class);
        util.exportExcel(response, list, "企业类型数据");
    }

    /**
     * 获取企业类型详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:companytype:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Integer id)
    {
        return success(sysCompanyTypeService.selectSysCompanyTypeById(id));
    }

    /**
     * 新增企业类型
     */
    @PreAuthorize("@ss.hasPermi('system:companytype:add')")
    @Log(title = "企业类型", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysCompanyType sysCompanyType)
    {
        return toAjax(sysCompanyTypeService.insertSysCompanyType(sysCompanyType));
    }

    /**
     * 修改企业类型
     */
    @PreAuthorize("@ss.hasPermi('system:companytype:edit')")
    @Log(title = "企业类型", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysCompanyType sysCompanyType)
    {
        return toAjax(sysCompanyTypeService.updateSysCompanyType(sysCompanyType));
    }

    /**
     * 删除企业类型
     */
    @PreAuthorize("@ss.hasPermi('system:companytype:remove')")
    @Log(title = "企业类型", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Integer[] ids)
    {
        return toAjax(sysCompanyTypeService.deleteSysCompanyTypeByIds(ids));
    }

    /**
     * 状态修改
     */
    @PreAuthorize("@ss.hasPermi('system:companytype:edit')")
    @Log(title = "企业类型", businessType = BusinessType.UPDATE)
    @PutMapping("/changeStatus")
    public AjaxResult changeStatus(@RequestBody SysCompanyType sysCompanyType)
    {
        return toAjax(sysCompanyTypeService.updateSysCompanyTypeStatus(sysCompanyType));
    }
}
